package bstsetcode.stanforduniversity18;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/15 21:58
 *
 * 非递归反转一个链表
 * 三个指针   移动指针 移动指针
 */
public class _16_reverse {





    public static ListNode reverse(ListNode head){

        ListNode prev = null;
        ListNode curr = head;

        while (curr != null) {

            ListNode nextTemp = curr.next;  //每次循环都会指向cur.next
            curr.next = prev; //链表指向前一个
            prev = curr;  //移动指针
            curr = nextTemp; //移动指针
        }
        return prev;

    }

    public static void main(String[] args) {
        int[] nums3 = {5,6,7,8,9};
        ListNode headA = new ListNode(nums3);
        ListNode reverse = _16_reverse.reverse(headA);
        System.out.println(reverse);
    }

}
